package com.ruoyi.customerService.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.customerService.domain.CsCustomerComplaintSheetBill;
import com.ruoyi.customerService.domain.vo.CsCustomerComplaintSheetBillVo;
import com.ruoyi.customerService.service.CsCustomerComplaintSheetBillService;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cs/customerComplaint")
@Api(tags = "客服中心-客诉工单账单")
public class CsCustomerComplaintSheetBillController {
    @Autowired
    private CsCustomerComplaintSheetBillService csCustomerComplaintSheetBillService;
    @Autowired
    private TableService tableService;

    @ApiOperation("汇总")
    @PostMapping("collect")
    public R collect(@RequestBody CsCustomerComplaintSheetBillVo vo){
        List<CsCustomerComplaintSheetBill> bills = csCustomerComplaintSheetBillService.collect(vo);
        if (bills == null || bills.size() == 0){
            return R.fail("暂无数据");
        }else {
            JSONObject jsonObject = new JSONObject();
            String[] fields = {"networkName", "contractAreaName", "oneNum", "oneAmount"
                    , "twoNum", "twoAmount", "threeNum", "threeAmount"
                    , "fourNum", "fourAmount", "fiveNum", "fiveAmount"
                    , "sexNum", "sexAmount", "sevenNum", "sevenAmount"
                    , "eightNum", "eightAmount", "nineNum", "nineAmount"
                    , "tenNum", "tenAmount", "elevenNum", "elevenAmount"
                    , "twelveNum", "twelveAmount", "thirteenNum", "thirteenAmount"
                    , "fourteenNum", "fourteenAmount", "fifteenNum", "fifteenAmount"
                    , "sixteenNum", "sixteenAmount", "seventeenNum", "seventeenAmount"
                    , "totalNum", "totalAmount"};
            InitTableVo initTableVo = new InitTableVo();
            initTableVo.setFields(fields);
            initTableVo.setCode("csCustomerComplaintSheetBill");
            jsonObject.put("list",PageInfo.info(bills));
            jsonObject.put("fields", tableService.initTable(initTableVo));
            return R.ok(jsonObject);
        }
    }

}
